<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>选择商品</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../../include/commonFile.jsp" %>
    <style type="text/css">
        .index-outside > section .section-main {
            min-width: 0px !important;
            padding: 0px 15px;
        }

        .index-outside > section {
            padding-bottom: 0px !important;
        }

        .layui-form-radio {
            height: 30px!important;
        }
    </style>
</head>
<body>
<!--头部-->
<div class="index-outside">
    <!--内容-->
    <section class="no-fix">
        <div class="section-main">
            <div class="layui-tab-item layui-show">
                <div class="layui-tab-item layui-show">
                    <div class="layui-tab layui-tab-brief" lay-filter="type">
                        <ul class="layui-tab-title" id="zc_tab">
                            <li class="layui-this">已上架商品</li>
                            <c:if test="${empty isMulti}">
                                <li>商品分类</li>
                            </c:if>
                        </ul>
                        <form class="layui-form" action="${ctx}/mall/goods/selectGoods.do" id="myForm" method="post">
                            <input type="hidden" name="pageNo" id="pageNo" value="${page.page}"/>
                            <input type="hidden" name="isMulti" value="${isMulti}" />
                            <div class="f-search-bar">
                                <div class="search-container">
                                    <ul class="search-form-content">
                                        <li class="form-item-inline"><label class="search-form-lable">商品名称</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="name" autocomplete="off" class="layui-input" value="${mallGoods.name}" placeholder="商品名称">
                                            </div>
                                        </li>
                                        <li class="form-item-inline">
                                            <div class="sub-btns">
                                                <a class="layui-btn layui-btn-danger" href="javascript:submitFunction('#myForm')">查询</a>
                                                <a class="layui-btn layui-btn-normal" href="javascript:resetFunction('#myForm')">重置</a>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </form>
                        <div class="c-time-list-content" style="padding-top: 0px;">
                            <input type="hidden" id="selectDatas"/>
                            <ul>
                                <table class="layui-table layui-form" lay-skin="line">
                                    <colgroup>
                                        <col width="50px">
                                        <col width="70px">
                                        <col>
                                        <%--<col width="150px">--%>
                                    </colgroup>
                                    <thead>
                                    <tr>
                                        <th></th>
                                        <th></th>
                                        <th>标题</th>
                                        <%--<th>创建时间</th>--%>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:forEach var="mg" items="${goodsList}">
                                        <tr data-id="${mg.id}" data-pic="${mg.pic}" data-name="${mg.name}">
                                            <td>
                                                <div>
                                                    <c:if test="${empty isMulti}">
                                                        <input type="radio" name="id" value="${mg.id}" lay-filter="radio" title="&nbsp;"/>
                                                    </c:if>
                                                    <c:if test="${not empty isMulti}">
                                                        <input type="checkbox" name="id" value="${mg.id}" lay-filter="chk" lay-skin="primary">
                                                    </c:if>
                                                </div>
                                            </td>
                                            <td>
                                                <img src="${mg.pic}" style="width: 50px; height: 50px"/>
                                            </td>
                                            <td>
                                                <div class="ellipsis-1" title="${mg.name}">${mg.name}</div>
                                            </td>
                                            <%--<td>--%>
                                                <%--<fmt:formatDate value="${mg.createDate}" pattern="yyyy-MM-dd HH:mm"/>--%>
                                            <%--</td>--%>
                                        </tr>
                                    </c:forEach>
                                    </tbody>
                                </table>
                                <div id="page_content" class="page-container"></div>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>
<!--底部-->
<%@include file="../../include/incScript.jsp" %>
<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript">
    $(function () {
        // 加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });
        layui.use(['form', 'element'], function () {
            var form = layui.form, element = layui.element;
            element.on('tab(type)', function (data) {
                if (data.index == 0) {
                    location.href = "${ctx}/mall/goods/selectGoods.do?isMulti=${isMulti}";
                } else if (data.index == 1) {
                    location.href = "${ctx}/mall/category/selectCategory.do?isMulti=${isMulti}";
                }
            });
        });

        $("#submitBtn").click(function () {
            $("#myForm").submit();
        });

        $("#resetBtn").click(function () {
            $("#myForm input[type=text]").val("");
        });
    });

    function doSubmit() {
        var length = $("[name=id]:checked").length;
        if (length == 0) {
            util.layerMsgError("请先选择")
            return false;
        }
        var _result = new Array();
        $("[name=id]:checked").each(function (index, ele) {
            var $tr = $(ele).closest("tr");
            var map = {
                targetId: $tr.data("id"),
                name: $tr.data("name"),
                pic: $tr.data("pic"),
                type: 2
            };
            _result.push(map);
        });
        $("#selectDatas").val(JSON.stringify(_result));
        return true;
    }
</script>
</body>
</html>